<!-- 自定义专题图表 可按照1920X1080设置固定尺寸 通过封装方法适配缩放尺寸 只可以替换数据 无其他高级属性自定义扩展 
  注:业务专题图表的图片存放文件夹名称需与当前文件名一致(打包时才会将图片打包进对应文件夹中)
  (1.并在aircim.webpack.build.component.config.js配置需要打包的文件2.npm run lib_c 执行打包命令  最后的组件会打包在components/grids中) -->
<template>
  <div class="scale-box" :id="dynamicIdName()">
    <!-- 设置动态类名以及交互方法 注!! 必须设置行内样式宽高同步 -->
    <div
      class="business-project-box animate__animated"
      style="width: 443px; height: 925px"
      :id="dynamicChildName()"
    >
      <BusinessNumber
        title="办理效率"
        unit="件"
        :value="6847"
        style="height: 156px;"
      ></BusinessNumber>
      <div
        class="bar-wrap"
        style="height: 220px;position: relative;margin-top: 16px;margin-bottom: 16px;"
      >
        <BarChart title="各生命周期办件统计"></BarChart>
      </div>
      <h2 class="h2_title">
        <span>各服务主题办件统计</span>
      </h2>
      <BarHorizontal
        :list="list"
        :containerHeight="containerHeight"
        :style="{ height: containerHeight + 'px' }"
      ></BarHorizontal>
      <h2 class="h2_title" style="margin-top: 20px;">
        <span>各渠道办件分布</span>
      </h2>
      <ul class="qd-list">
        <li class="qd-item">
          <p>线下办件量</p>
          <div>
            <span class="num"><em>38135</em>件</span
            ><span class="num"><em>38135</em>%</span>
          </div>
        </li>
        <li class="qd-item">
          <p>线上办件量</p>
          <div>
            <span class="num"><em>38135</em>件</span
            ><span class="num"><em>38135</em>%</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
//混入封装方法
import encapsulation from "../../utils/aircimGird";
import BusinessNumber from "../../components/elements/BusinessNumber.vue";
import BarChart from "../../components/elements/BarChart.vue";
import BarHorizontal from "../../components/elements/BarHorizontal.vue";
export default {
  name: "ancientCanalsLeft",
  grid_specification: "aircim_grid_1x1",
  mixins: [encapsulation],
  components: { BusinessNumber, BarChart, BarHorizontal },
  data() {
    return {
      resizeObserver: null,
      //动态Id
      timestamp: null,
      containerHeight: 300,
      list: [
        {
          name: "名称名称名称名称名称名称名称名称名称名称名称名称",
          value: 50,
          total: 100,
          unit: "%",
        },
        {
          name: "名称名称名称",
          value: 50,
          total: 100,
          unit: "%",
        },
        {
          name: "名称名称名称",
          value: 50,
          total: 100,
          unit: "%",
        },
        {
          name: "名称名称名称",
          value: 50,
          total: 100,
          unit: "%",
        },
        {
          name: "名称名称名称",
          value: 50,
          total: 100,
          unit: "%",
        },
        {
          name: "名称名称名称",
          value: 50,
          total: 100,
          unit: "%",
        },
        {
          name: "名称名称名称",
          value: 50,
          total: 100,
          unit: "%",
        },
      ],
    };
  },
  methods: {
    //初始化方法
    initGrid() {},
    //刷新数据方法
    refreshData(val) {
      this.echartdata = val.echartdata;
    },
    refreshConfig(val) {},
    //监听外部盒子的大小 然后对数据井行缩放
    scaleFn() {
      const parentBox = document.getElementById(`dynamic-${this.timestamp}`);
      const childBox = document.getElementById(
        `dynamicChild-${this.timestamp}`
      );
      const parentWidth = parentBox.offsetWidth;
      const parentHeight = parentBox.offsetHeight;
      const childWidth = childBox.offsetWidth;
      const childHeight = childBox.offsetHeight;
      let scaleX, scaleY;
      if (parentWidth < childWidth || parentHeight < childHeight) {
        const scaleBasedOnWidth = parentWidth / childWidth;
        const scaleBasedOnHeight = parentHeight / childHeight;
        scaleX = scaleBasedOnWidth;
        scaleY = scaleBasedOnHeight;
      } else {
        scaleX = parentWidth / childWidth;
        scaleY = parentHeight / childHeight;
      }
      childBox.style.transform = `scale(${scaleX}, ${scaleY})`;
    },
    // 监听盒子变化
    listenChangeFn() {
      let that = this;
      const element = document.getElementById(`dynamic-${this.timestamp}`);
      // console.log(element, "element");
      if (element) {
        new ResizeObserver(() => {
          // 处理元素大小变化的逻辑
          that.scaleFn();
        }).observe(element);
      }
    },
    // 绑定动画样式 animate__flash
    bindAnimationFn(animateName) {
      if (animateName != null) {
        this.dynamicClassName = animateName;
      }
    },
    //定义唯一ID名
    dynamicIdName() {
      return `dynamic-${this.timestamp}`;
    },
    //定义唯一ID名
    dynamicChildName() {
      return `dynamicChild-${this.timestamp}`;
    },
  },
  mounted() {
    this.timestamp = new Date().getTime();
    this.$nextTick(() => {
      // 监听盒子变化
      this.listenChangeFn();
    });
  },

  computed: {},
  // 销毁监听
  beforeDestroy() {
    // 组件销毁前停止监听
    if (this.resizeObserver) {
      this.resizeObserver.disconnect();
    }
    if (this.requestTime != null) {
      clearInterval(this.requestTime);
    }
  },
};
</script>
<style lang="scss" scoped>
@import "../../static/assets/common.scss";
</style>
<style lang="scss" scoped>
.scale-box {
  width: 100%;
  height: 100%;
  position: relative;
}

.business-project-box {
  padding: 0px 20px;
  box-sizing: border-box;
  position: absolute;
  transform-origin: left top;
  display: flex;
  flex-direction: column;
  background-image: url(../../../thumbnail/backImg/new-border-green.png);
  background-size: 100% 100%;
  background-repeat: no-repeat;
}
.qd-list {
  margin-top: 15px;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  .qd-item {
    padding-top: 5px;
    width: calc(50% - 12px);
    height: 91px;
    background: url(../../static/assets/BusinessProject/qdbg.png) no-repeat left
      center;
    background-size: 100% 100%;
    & > p {
      font-size: 16px;
      font-weight: 500;
      line-height: 30px;
      text-align: center;
    }
    & > div {
      padding: 0 18px;
      margin-top: 17px;
      display: flex;
      align-items: center;
      span {
        width: 50%;
      }
      em {
        font-size: 22px;
        color: #0ff;
      }
      span:last-of-type {
        text-align: right;
      }
    }
    &:last-of-type {
      em {
        color: #ffbd3c;
      }
    }
  }
}
</style>
<style>
.business-project-box .business-efficiency-box {
  background-image: none !important;
}
</style>
